package com.wdg.controller;

import com.wdg.fegin.IndexFegin;
import com.wdg.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin  //解决跨域问题
@RequestMapping("/index_consumer")
public class IndexController {

    @Autowired
    private IndexFegin indexFegin;

    //今日推荐，根据推荐表查出
    @GetMapping("/getCookBookForIndex")
    List<TodayRecommend> getCookBookForIndex(){
        return indexFegin.getCookBookForIndex();
    }

    //轮播图，根据轮播表查出
    @GetMapping("/getCircleImageForIndex")
    List<CircleImage> getCircleImageForIndex(){
        return indexFegin.getCircleImageForIndex();
    }

    //最新菜谱,根据上传时间查出
    @GetMapping("/getNewCookBookForIndex")
    List<Cookbook> getNewCookBookForIndex(){
        return indexFegin.getNewCookBookForIndex();
    }

    //热门分类,随机查询分类展示
    @GetMapping("/getHotFoodForIndex")
    List<Food> getHotFoodForIndex(){
        return indexFegin.getHotFoodForIndex();
    }

    //    根据cbid查询这一个菜谱的所以信息
    @GetMapping("/getCookBookBycbid/{cbid}")
    Cookbook getCookBookByCbid(@PathVariable("cbid") String cbid){
        return indexFegin.getCookBookByCbid(cbid);
    }
    @GetMapping("/addCookBookView/{cbid}")
    void addCookBookView(@PathVariable("cbid") String cbid){
         indexFegin.addCookBookView(cbid);
    }

    //查询分类
    @GetMapping("/getAllSort")
    public List<Foodtitle> getAllSort() {
        return indexFegin.getAllSort();
    }

    @GetMapping("/getCookBookByFid")
    public List<Sort> getCookBookByFid(@RequestParam("fid") int fid, @RequestParam("pageId") int pageId) {
        return indexFegin.getCookBookByFid(fid,pageId);
    }
}
